﻿using UniRx;
using UnityEngine;

[RequireComponent(typeof(BoxCollider2D))]
public abstract class UnitTerrainCheckerBase : USaBehaviour
{
    /// <summary>
    /// 实体引用
    /// </summary>
    protected UnitEntityBase entity { get; private set; }

    /// <summary>
    /// 获取有效碰撞layers
    /// </summary>
    protected int layers { get; private set; }

    public void Init(UnitEntityBase entity)
    {
        this.entity = entity;
        layers = Physics2D.GetLayerCollisionMask(gameObject.layer);
        entity.lifeCycle.GetLifeCycleStream(UnitLifeCycle.LifeType.TerrainChecker).WhenActive(this).Subscribe(UpdateTerrainInfo).AddTo(entity);
        OnInit();
    }

    protected virtual void OnInit() { }

    protected abstract void UpdateTerrainInfo(long _);
}